package com.isorf.controller;

import com.github.pagehelper.PageInfo;
import com.isorf.pojo.ShoeType;
import com.isorf.service.ShoeTypeService;
import com.isorf.util.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "鞋子类型管理")
@RestController
@RequestMapping("/shoeType")
public class ShoeTypeController {
    @Autowired
    private ShoeTypeService shoeTypeService;

    /**
     * 新增鞋子类型
     */
    @PostMapping("/add")
    public ResponseResult<Boolean> addShoeType(@RequestBody ShoeType shoeType) {
        Boolean result = shoeTypeService.addShoeType(shoeType);
        if (result) {
            return ResponseResult.success(ResponseResult.SUCCESS, "添加成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "添加失败");
        }
    }

    /**
     * 删除鞋子类型
     */
    @PostMapping("/delete")
    public ResponseResult<Boolean> deleteShoeType(@RequestParam int typeId) {
        Boolean result = shoeTypeService.deleteShoeType(typeId);
        if (result) {
            return ResponseResult.success(ResponseResult.SUCCESS, "删除成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "删除失败");
        }
    }

    /**
     * 更新鞋子类型
     */
    @PostMapping("/update")
    public ResponseResult<Boolean> updateShoeType(@RequestBody ShoeType shoeType) {
        Boolean result = shoeTypeService.updateShoeType(shoeType);
        if (result) {
            return ResponseResult.success(ResponseResult.SUCCESS, "更新成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "更新失败");
        }
    }

    /**
     * 根据ID查询鞋子类型
     */
    @GetMapping("/getById")
    public ResponseResult<ShoeType> getShoeTypeById(@RequestParam int typeId) {
        ShoeType result = shoeTypeService.getShoeTypeById(typeId);
        if (result != null) {
            return ResponseResult.success(ResponseResult.SUCCESS, "查询成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "查询失败");
        }
    }

    /**
     * 分页查询鞋子类型
     */
    @GetMapping("/pageList")
    public ResponseResult<PageInfo<ShoeType>> pageList(@RequestParam(defaultValue = "1") int pageNum, 
                                                       @RequestParam(defaultValue = "5") int pageSize) {
        PageInfo<ShoeType> result = shoeTypeService.pageList(pageNum, pageSize);
        if (result != null && result.getList().size() > 0) {
            return ResponseResult.success(ResponseResult.SUCCESS, "查询成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "查询失败");
        }
    }

    /**
     * 查询全部鞋子类型
     */
    @GetMapping("/getAll")
    public ResponseResult<List<ShoeType>> getAllShoeTypes() {
        List<ShoeType> result = shoeTypeService.getAllShoeTypes();
        if (result != null && result.size() > 0) {
            return ResponseResult.success(ResponseResult.SUCCESS, "查询成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "没有鞋子类型信息");
        }
    }
} 